package com.atguigu.gmall.file;

import org.junit.Test;

import java.util.concurrent.*;

public class ThreadDemo {


    //第一个线程
/*    @Test
    public void testThread1(){

        System.out.println(Thread.currentThread().getName());

        new Thread(new MyRunable(),"aaa").start();

    }*/

    public static void main(String[] args) throws Exception {
 /*       System.out.println(Thread.currentThread().getName());
        //new Thread(new MyRunable(),"aaa").start();
        //Lambda 表达 式
        new Thread(() -> {
            System.out.println("干活代码bbb");
        },"bbb").start();
        //
        FutureTask futureTask = new FutureTask(() -> {
            return "ccccccc";
        });
        new Thread(futureTask,"ccc").start();
        System.out.println(futureTask.get());
*/
        ///

        ThreadPoolExecutor threadPoolExecutor =
                new ThreadPoolExecutor(2,
                        5,
                        10,
                        TimeUnit.SECONDS,
                        new ArrayBlockingQueue(100)
                    );
        FutureTask futureTaskThreadPool = new FutureTask(() -> {
            //干活代码
            return "dddddd";
        });
        threadPoolExecutor.execute(futureTaskThreadPool);
        System.out.println(futureTaskThreadPool.get());

    }
}
class MyRunable implements Runnable{

    @Override
    public void run() {
        System.out.println("干活代码");
    }
}
class MyCallable implements Callable{

    @Override
    public Object call() throws Exception {
        return null;
    }
}
